#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1010;
int f[N];
int price[N];
int n, m;
int main()
{
	while (cin>>n) {
		if (n == 0) {
			break;
		}
		memset(f, 0, sizeof(f));
		memset(price, 0, sizeof(price));
		for (int i = 1; i <= n; i++) {
			cin >> price[i];
		}
		cin >> m;
		if (m < 5) {
			cout << m << endl;
			continue;
		}
		sort(price + 1, price + n + 1);
		m -= 5;
		for (int i = 1; i < n; i++) {
			for (int j = m; j >= price[i]; j--) {
				f[j] = max(f[j], f[j - price[i]] + price[i]);	
			}
		}
		cout << m  +  5 - f[m] - price[n] << endl;
	}
	return 0;
}